package com.geralt.userservice.controller;

import com.geralt.userservice.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    MongoTemplate dao;

    @RequestMapping(value = "/getAll", method= RequestMethod.GET)
    public String getAllUser(){
        return dao.findAll(User.class).toString();
    }

    @RequestMapping(value = "/get", method= RequestMethod.GET)
    public String getAllUser(@RequestParam(value = "username")String username,@RequestParam(value="password")String password  ){
        Criteria criteria = Criteria.where("username").in(username);
        List<User> users = dao.find(Query.query(criteria), User.class);
        return users.toString();
    }
}
